package com.assignwork.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
public class WorkArrangeLandVO {

    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;
    private String workNo;
    @JsonSerialize(using = ToStringSerializer.class)
    private Long area;
    private String areaNames;
    private String loadType;
    private String loadTypeName;
    private String packageBulk;
    private String packageBulkName;
    private String landWorkType;
    private String landWorkTypeName;
    @JsonFormat(pattern = DateUtil.PATTERN_DATE)
    @DateTimeFormat(pattern = DateUtil.PATTERN_DATE)
    private LocalDate planDate;
    private String remark;
    private String timeSpace;
    private String timeSpaceName;
    private BigDecimal workTon;
    private String cargoType;
    private String shipName;

    List<WorkArrangeFixedMachineVO> listFixedMachine;
    List<WorkArrangeMachinesVO> listFlowMachine;
    List<AssignWorkVO> listAssignWork;
    List<WorkArrangeWorkersVO> listWorker;

    public Map<String, AssignWorkVO> getMapFixedAssignWork() {
        if (Func.isNotEmpty(listAssignWork)) {
            return listAssignWork.stream().filter(i -> "FIXED_MACHINE_LAND".equals(i.getWorkType())).collect(Collectors.toMap(i -> i.getArrangeId().toString(), a -> a,(k1, k2)->k1));
        }

        return null;
    }

    public Map<String, AssignWorkVO> getMapFlowAssignWork() {
        if (Func.isNotEmpty(listAssignWork)) {
            return listAssignWork.stream().filter(i -> "FLOW_MACHINE_LAND".equals(i.getWorkType())).collect(Collectors.toMap(i -> i.getArrangeId().toString(), a -> a,(k1, k2)->k1));
        }
        return null;
    }

    public Map<String, AssignWorkVO> getMapWorkerAssignWork() {
        if (Func.isNotEmpty(listAssignWork)) {
            return listAssignWork.stream().filter(i -> "LOADER_LAND".equals(i.getWorkType())).collect(Collectors.toMap(i -> i.getArrangeId().toString(), a -> a,(k1, k2)->k1));
        }

        return null;
    }
    public Map<String, AssignWorkVO> getMapRenterAssignWork() {
        if (Func.isNotEmpty(listAssignWork)) {
            return listAssignWork.stream().filter(i -> "RENTER_MACHINE_LAND".equals(i.getWorkType())).collect(Collectors.toMap(i -> i.getArrangeId().toString(), a -> a,(k1, k2)->k1));
        }

        return null;
    }
}
